//
//  ZBMoBanTenViewController.m
//  MoBan
//
//  Created by apple on 16/7/21.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZBMoBanTenViewController.h"
#import "ZBSegScrollview.h"
@interface ZBMoBanTenViewController ()<UIScrollViewDelegate,ZBSegScrollviewDeleget>
/**
 盛放控制器的数组
 */
@property(nonatomic,strong)NSMutableArray *array;
@property(nonatomic,strong)UIScrollView *scrollview;
@property(nonatomic,strong)ZBSegScrollview *segscrollview;
@end

@implementation ZBMoBanTenViewController
-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray arrayWithObjects:@"text1ViewController",@"text2ViewController",@"text3ViewController",@"text4ViewController",@"text5ViewController",@"text6ViewController",@"text7ViewController", nil];
    }
    return _array;
}
-(UIScrollView *)scrollview
{
    if (!_scrollview) {
        _scrollview = [[UIScrollView alloc]init];
        _scrollview.frame = CGRectMake(0,self.segscrollview.bottom , KscrW, KscrH-KBar1-self.segscrollview.bottom);
        _scrollview.contentSize = CGSizeMake(KscrW*self.array.count, KscrH-KBar1-self.segscrollview.bottom);
        _scrollview.delegate = self;
        _scrollview.pagingEnabled = YES;
    }
    return _scrollview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    ZBSegScrollview *scrview = [[ZBSegScrollview alloc]initWithFrame:CGRectMake(0, 0, KscrW, 60)];
//    scrview.array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    scrview.deleget = self;
    self.segscrollview = scrview;
    
    
    [self.view addSubview:scrview];
    [self.view addSubview:self.scrollview];
    [self addSubViewConter];
    // Do any additional setup after loading the view.
}
/**
 添加自控制器的view
 */
-(void)addSubViewConter
{

    for (NSInteger i=0; i<self.array.count; i++) {
        UIViewController * vc = [[NSClassFromString(self.array[i]) alloc]init];
        [self addChildViewController:vc];
        vc.view.frame = CGRectMake(KscrW *i, 0, KscrW, KscrH-KBar1-self.segscrollview.bottom);
        [self.scrollview addSubview:vc.view];
    }

}
/**
 头部控件的代理
 */
-(void)ZBSegScrollview:(ZBSegScrollview*)segScrollview didClicAtIndex:(NSInteger)index
{
    [UIView animateWithDuration:0.5 animations:^{
        self.scrollview.contentOffset = CGPointMake(KscrW*index, 0);
    }];
    

}
/**
 此处是为了设置偏移量如果不设置偏移量
 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.segscrollview ZBScrollviewSetLineViewX:scrollView.contentOffset.x];
    
//    NSLog(@"测试%@",NSStringFromCGPoint(scrollView.contentOffset));

}
@end
